package cn.wolfcode.consumer_02._03_consumer_type;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws Exception {
        //1 创建消费者对象
        DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer("consumer-demo2");
        //2 设置名字服务的地址
        defaultMQPullConsumer.setNamesrvAddr("127.0.0.1:9876");
        //3 启动消费者
        defaultMQPullConsumer.start();
        //4 拉取消息
        PullResult pullResult = defaultMQPullConsumer.pull(new MessageQueue("04-consumer-type", "broker-a", 0), "*", 0, 10);
        //5 获取消息集合
        List<MessageExt> list = pullResult.getMsgFoundList();
        for (MessageExt messageExt : list) {
            System.out.println("消息是:" + new String(messageExt.getBody()));
        }
    }
}
